package org.sky.framework.rest;

import org.sky.framework.exception.AbstractException;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(description = "Rest消息")
public class RestEntity<T> {

	@ApiModelProperty(value = "渠道")
	protected String channel;

	@ApiModelProperty(value = "消息主体")
	protected T entity;

	@ApiModelProperty(value = "是否成功")
	protected boolean success = true;

	@ApiModelProperty(value = "异常编码")
	protected String errcode;

	@ApiModelProperty(value = "异常信息")
	protected String errmsg;

	public void error(Throwable e) {
		errcode = "500";
		errmsg = "系统繁忙，稍后再试！";
		success = false;
		entity = null;
		if (e instanceof AbstractException) {
			AbstractException be = (AbstractException) e;
			errcode = be.getErrcode();
			errmsg = be.getErrmsg();
		}
	}

	public String getChannel() {
		return channel;
	}

	public void setChannel(String channel) {
		this.channel = channel;
	}

	public T getEntity() {
		return entity;
	}

	public void setEntity(T entity) {
		this.entity = entity;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getErrcode() {
		return errcode;
	}

	public void setErrcode(String errcode) {
		this.errcode = errcode;
	}

	public String getErrmsg() {
		return errmsg;
	}

	public void setErrmsg(String errmsg) {
		this.errmsg = errmsg;
	}

}
